/*
*	Collect some debug function for stm32
* -------------------------------------	
*	20180610			Dawei					initial
*/
#ifndef __DEBUG_H__
#define __DEBUG_H__

#include "typedef.h"
#include <stdio.h>

#define DEBUG_LOG_EN										//log function enable

#ifdef DEBUG_LOG_EN
//uart
#define LOG_UART_PORT										//print log to uart
#define LOG_UART_DMA_EN									//use DMA to uart

//swo
//#define LOG_SWO_PORT										//print log to SWO
//

//simu
//#define LOG_IO_SIMU												//print log to simulated uart

#endif

#define LOG_MAX_LEN					1024				//log buffer length		
#define LOG_UART_BAUD				115200			//uart baudrate

#define LOG_DEV_TYPE_LATER					1		//print log async
#define LOG_DEV_TYPE_DIRECT					2		//print log sync


typedef struct{
		u8 (*init)(void* arg);
		u8 (*print)(u8 ch);
		u8 (*print_dma)(u8* buffer, u32 len);
}log_func;


typedef struct {
		volatile u8 		type;
		u8*		buffer;
		volatile u32		write_idx;
		volatile u32		read_idx;
		volatile u32		dma_read_idx;
		//uart
		log_func*				uart_log_func;
		//SWO
		log_func*				swo_log_func;
	
}log_dev;




u8 log_init(u8 type, void* arg);
int fputc(int ch, FILE *f);
void print_ch(u8 ch);
void output_ch(void);

#ifdef DEBUG_LOG_EN
#define DEBUG(...)	printf("usb_printer:"__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#endif

